home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 8 / Engine / Engine.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-20  |  5.5 KB  |  151 lines

  1. //-----------------------------------------------------------------------------
  2. // The primary engine header file. This file links the entire engine together
  3. // and is the only header file that needs to be included in any project using
  4. // the engine.
  5. //
  6. // Programming a Multiplayer First Person Shooter in DirectX
  7. // Copyright (c) 2004 Vaughan Young
  8. //-----------------------------------------------------------------------------
  9. #ifndef ENGINE_H
  10. #define ENGINE_H
  11.  
  12. //-----------------------------------------------------------------------------
  13. // DirectInput Version Define
  14. //-----------------------------------------------------------------------------
  15. #define DIRECTINPUT_VERSION 0x0800
  16.  
  17. //-----------------------------------------------------------------------------
  18. // System Includes
  19. //-----------------------------------------------------------------------------
  20. #include <stdio.h>
  21. #include <tchar.h>
  22. #include <windowsx.h>
  23.  
  24. //-----------------------------------------------------------------------------
  25. // DirectX Includes
  26. //-----------------------------------------------------------------------------
  27. #include <d3dx9.h>
  28. #include <dinput.h>
  29. #include <dplay8.h>
  30. #include <dmusici.h>
  31.  
  32. //-----------------------------------------------------------------------------
  33. // Macros
  34. //-----------------------------------------------------------------------------
  35. #define SAFE_DELETE( p )       { if( p ) { delete ( p );     ( p ) = NULL; } }
  36. #define SAFE_DELETE_ARRAY( p ) { if( p ) { delete[] ( p );   ( p ) = NULL; } }
  37. #define SAFE_RELEASE( p )      { if( p ) { ( p )->Release(); ( p ) = NULL; } }
  38.  
  39. //-----------------------------------------------------------------------------
  40. // Engine Includes
  41. //-----------------------------------------------------------------------------
  42. #include "Resource.h"
  43. #include "LinkedList.h"
  44. #include "ResourceManagement.h"
  45. #include "Geometry.h"
  46. #include "Font.h"
  47. #include "Scripting.h"
  48. #include "DeviceEnumeration.h"
  49. #include "Input.h"
  50. #include "Network.h"
  51. #include "SoundSystem.h"
  52. #include "BoundingVolume.h"
  53. #include "Material.h"
  54. #include "Mesh.h"
  55. #include "RenderCache.h"
  56. #include "State.h"
  57.  
  58. //-----------------------------------------------------------------------------
  59. // Engine Setup Structure
  60. //-----------------------------------------------------------------------------
  61. struct EngineSetup
  62. {
  63.     HINSTANCE instance; // Application instance handle.
  64.     GUID guid; // Application GUID.
  65.     char *name; // Name of the application.
  66.     float scale; // Unit scale in meters/unit.
  67.     unsigned char totalBackBuffers; // Number of back buffers to use.
  68.     void (*HandleNetworkMessage)( ReceivedMessage *msg ); // Network message handler.
  69.     void (*StateSetup)(); // State setup function.
  70.     void (*CreateMaterialResource)( Material **resource, char *name, char *path ); // Material resource creation function.
  71.  
  72.     //-------------------------------------------------------------------------
  73.     // The engine setup structure constructor.
  74.     //-------------------------------------------------------------------------
  75.     EngineSetup()
  76.     {
  77.         GUID defaultGUID = { 0x24215591, 0x24c0, 0x4316, { 0xb5, 0xb2, 0x67, 0x98, 0x2c, 0xb3, 0x82, 0x54 } };
  78.  
  79.         instance = NULL;
  80.         guid = defaultGUID;
  81.         name = "Application";
  82.         scale = 1.0f;
  83.         totalBackBuffers = 1;
  84.         HandleNetworkMessage = NULL;
  85.         StateSetup = NULL;
  86.         CreateMaterialResource = NULL;
  87.     }
  88. };
  89.  
  90. //-----------------------------------------------------------------------------
  91. // Engine Class
  92. //-----------------------------------------------------------------------------
  93. class Engine
  94. {
  95. public:
  96.     Engine( EngineSetup *setup = NULL );
  97.     virtual ~Engine();
  98.  
  99.     void Run();
  100.  
  101.     HWND GetWindow();
  102.     void SetDeactiveFlag( bool deactive );
  103.  
  104.     float GetScale();
  105.     IDirect3DDevice9 *GetDevice();
  106.     D3DDISPLAYMODE *GetDisplayMode();
  107.     ID3DXSprite *GetSprite();
  108.  
  109.     void AddState( State *state, bool change = true );
  110.     void RemoveState( State *state );
  111.     void ChangeState( unsigned long id );
  112.     State *GetCurrentState();
  113.  
  114.     ResourceManager< Script > *GetScriptManager();
  115.     ResourceManager< Material > *GetMaterialManager();
  116.     ResourceManager< Mesh > *GetMeshManager();
  117.  
  118.     Input *GetInput();
  119.     Network *GetNetwork();
  120.     SoundSystem *GetSoundSystem();
  121.  
  122. private:
  123.     bool m_loaded; // Indicates if the engine is loading.
  124.     HWND m_window; // Main window handle.
  125.     bool m_deactive; // Indicates if the application is active or not.
  126.  
  127.     EngineSetup *m_setup; // Copy of the engine setup structure.
  128.     IDirect3DDevice9 *m_device; // Direct3D device interface.
  129.     D3DDISPLAYMODE m_displayMode; // Display mode of the current Direct3D device.
  130.     ID3DXSprite *m_sprite; // Sprite interface for rendering 2D textured primitives.
  131.     unsigned char m_currentBackBuffer; // Keeps track of which back buffer is at the front of the swap chain.
  132.  
  133.     LinkedList< State > *m_states; // Linked list of states.
  134.     State *m_currentState; // Pointer to the current state.
  135.     bool m_stateChanged; // Indicates if the state changed in the current frame.
  136.  
  137.     ResourceManager< Script > *m_scriptManager; // Script manager.
  138.     ResourceManager< Material > *m_materialManager; // Material manager.
  139.     ResourceManager< Mesh > *m_meshManager; // Mesh manager.
  140.  
  141.     Input *m_input; // Input object.
  142.     Network *m_network; // Network object.
  143.     SoundSystem *m_soundSystem; // Sound system.
  144. };
  145.  
  146. //-----------------------------------------------------------------------------
  147. // Externals
  148. //-----------------------------------------------------------------------------
  149. extern Engine *g_engine;
  150.  
  151. #endif